package cn.stronglink.asset.message.mq.dam.handle;

import cn.stronglink.asset.message.mq.dam.message.MQMessageOfDAM;
import cn.stronglink.asset.module.dam.service.DamService;
import cn.stronglink.asset.module.dam.service.IDamService;
import cn.stronglink.suite.core.util.ContextUtils;

public class AssetDataHandle extends AbstractReturnExceptionHandle{
	protected final static String TOPIC_NAME = "serviceToDam";
	protected final static String ACTION_CODE = "getAssetList";
	protected final static String SEND_ACTION_CODE= "getAssetList_return";
	protected IDamService damService =(DamService)ContextUtils.getBean("sensorService");
//	private ReaderInfoSender topicSender = (ReaderInfoSender) ContextUtils.getBean("readerInfoSender");
	@Override
	public boolean isHandle(MQMessageOfDAM msg) {
		if(msg.getActioncode().equals(ACTION_CODE)) {
			return true;
		}
		return false;
	}

	@Override
	protected void handleMessage(MQMessageOfDAM msg) {
//		GetAssetListParamsEntity assetDataParamsEntity =  ((JSONObject)msg.getAwsPostdata()).toJavaObject(GetAssetListParamsEntity.class);

//		@SuppressWarnings("unchecked")
//		Page<ItAssetVo> page = (Page<ItAssetVo>) getPage(assetDataParamsEntity);
//		Page<ItAssetVo> data = damService.qryAssetInfoByRackCode(page, assetDataParamsEntity.getRackCode());
//		JSONObject object = resultJson(data);
//		StringBuffer sb = new StringBuffer();
//		MQMessageOfDAM message = new MQMessageOfDAM();
//		message.setActioncode(SEND_ACTION_CODE);
//		message.setAwsPostdata(object);
//		message.setTimestamp(System.currentTimeMillis());
//		
//		String json = JSON.toJSONString(message);
//		topicSender.send(TOPIC_NAME,json);
//		logger.info("发送资产列表命令:{}",json);
	}
	
	/** 分页查询 */
//	private  Object getPage(GetAssetListParamsEntity assetDataParamsEntity) {
//		Integer current = 1;
//		Integer size = 10;
//		String orderBy = "id_";
//		if (DataUtil.isNotEmpty(assetDataParamsEntity.getPageNum())) {
//			current = assetDataParamsEntity.getPageNum();
//		}
//		if (DataUtil.isNotEmpty(assetDataParamsEntity.getPageSize())) {
//			size = assetDataParamsEntity.getPageSize();
//		}
//		if (size == -1) {
//			return new Page<Long>();
//		}
//		Page<Long> page = new Page<Long>(current, size, orderBy);
//		page.setAsc(false);
//		return page;
//	}
	
//	private JSONObject resultJson(Page<ItAssetVo> data) {
//		JSONObject json = null;
//		Map<String,Object> modelMap = new HashMap<>();
//		if (data instanceof Page) {
//			Page<?> page = (Page<?>) data;
//			modelMap.put("data", page.getRecords());
//			modelMap.put("current", page.getCurrent());
//			modelMap.put("size", page.getSize());
//			modelMap.put("pages", page.getPages());
//			modelMap.put("iTotalRecords", page.getTotal());
//			modelMap.put("iTotalDisplayRecords", page.getTotal());
//		} else if (data instanceof List<?>) {
//			modelMap.put("data", data);
//			modelMap.put("iTotalRecords", ((List<?>) data).size());
//			modelMap.put("iTotalDisplayRecords", ((List<?>) data).size());
//		} else {
//			modelMap.put("data", data);
//		}
//		json = (JSONObject) JSONObject.toJSON(modelMap);
//		return json;
//	}

}
